package com.example.demo.service.people;


import com.example.demo.dao.people.CustomerDAO;
import com.example.demo.model.people.Customer;
import com.example.demo.model.people.Provider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerService {
    @Autowired
    private CustomerDAO dao;

    public List<Customer> selectAll() {
        return dao.selectAll();
    }

    public Integer addCustomer(Customer customer) {
        return dao.addCustomer(customer);
    }

    public Integer deleteById(Integer customer_id) {
        return dao.deleteById(customer_id);
    }

    public Integer updateById(Customer customer) {
        return dao.updateById(customer);
    }

    public List<Customer> findcustomer(String customer_name, String connectionpersion, String customer_phone) {
        return dao.findcustomer(customer_name, connectionpersion, customer_phone);
    }

    public Boolean save(Customer customer) {
        Boolean flag = false;

        if (customer.getCustomer_id() != null) {
            flag = dao.updateById(customer) == 1;
        } else {
            flag = dao.addCustomer(customer) == 1;
        }

        return flag;
    }
}
